package com.sifa.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.sifa.springcloud.entities.CommentResult;
import com.sifa.springcloud.service.PaymentHystrixTest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
//@DefaultProperties(defaultFallback = "globalExceptionHandler2")
public class OrderOpenfeignHystrixController {
      @Resource
    private PaymentHystrixTest paymentHystrixTest;

    @GetMapping("payment/hystrix/ok/{id}")
    public String payment(@PathVariable("id")Integer id){
//        System.out.println(10/0);
        return paymentHystrixTest.payment(id);
    }
    @GetMapping("payment/hystrix/error/{id}")
//    @HystrixCommand
//    @HystrixCommand(fallbackMethod = "paymentTimeoutOrExceptionHandler",
//            commandProperties = @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500"))
    public String paymentError(@PathVariable("id")Integer id){
//        System.out.println(10/0);
        return paymentHystrixTest.paymentError(id);
    }

    public String paymentTimeoutOrExceptionHandler(Integer id){
        return "系统出问题了，请稍后再试";
    }
    public String globalExceptionHandler(){
        return "?系统有问题";
    }
    public String globalExceptionHandler2(){
        return "?@系统问题";
    }
}
